<?php
/**
 * beimuaihui System
 * Copyright(c) 2011-2020 beimuaihui.
 * @license    http://www.gnu.org/licenses/gpl.html     This software Under GPL V3 License 
 * beimuaihui@gmail.com
 * http://code.google.com/p/beimuaihui/
 * $Id: ReportController.php 197 2011-02-18 12:45:33Z beimuaihui $
 */


class Mall_EdureportController extends Baogg_Controller_Action {

	function init() 
	{		
		Baogg_Language::loadFile("user");
	}
	
	function listAction(){
		
		$params=$this->getRequest()->getParams();
		$period=5;
		$arr_year=array();
		$cur_year=(int)date("Y");
		$period=5;
		for($i=$cur_year;$i>$cur_year-$period;$i--){
			$arr_year[]=$i;
		}

		if(isset($params['user_id'])){
			$url_param['user_id']=$params['user_id'];
		}else{
			$url_param['user_id']=$_SESSION['admin']['user']['user_id'];
		}
		if(isset($params['begin_time'])){
			$url_param['begin_time']=(int)$params['begin_time'];
		}else{
			$url_param['begin_time']=(int)date("Y");
		}
		if(isset($params['model_id'])){
			$url_param['model_id']=$params['model_id'];
		}
		
		

		$arr_url=$params;
		$arr_url['action']='data';
		$arr_url=array_merge($arr_url,$url_param);
		$arr_user_url=array("module"=>"system","controller"=>"user","action"=>"store");
		
		$cur_year=(int)date("Y");
		$arr_year=array();
		for($i=$cur_year;$i>$cur_year-$period;$i--){
			$arr_year[]=$i;
		}
		
		$this->view->url=Baogg_Controller_Url::generate($arr_url);
		$this->view->user_url=Baogg_Controller_Url::generate($arr_user_url);
		
		$this->view->url=Baogg_Controller_Url::generate($arr_url);

		$this->view->user_url=Baogg_Controller_Url::generate($arr_user_url);
		//echo '<pre>';print_r($arr_user_url);var_dump(Baogg_Controller_Url::generate($arr_url));exit;
		$this->view->user_id=$url_param['user_id'];
		
		$this->view->begin_time_data=Zend_Json::encode($arr_year);
		$this->view->begin_time=$url_param['begin_time'];
		$this->view->arr_year=Zend_Json::encode($arr_year);
		$this->view->action=$params['action']."content";
		
	}




	function dataAction(){
		//loaded user info
		$params=$this->getRequest()->getParams();

		

		if(isset($params['user_id'])){
			$user_id=(int)$params['user_id'];
		}else{
			$user_id=(int)$_SESSION['admin']['user']['user_id'];
		}
		if(isset($params['begin_time'])){
			$begin_time=(int)$params['begin_time'];
		}else{
			$begin_time=(int)date("Y");
		}
		if(isset($params['model_id'])){
			$model_id=(int)$params["model_id"];
		}

		$User=new User();
		$rs_user=$User->getOne($user_id);		
		$this->view->user=@$rs_user[0];
		
		//loaded model
		
		if(!$model_id){
			throw new Exception(BAOGG_LANGUAGE::get('hack'));
		}
		$ModelTable=new ModelTable($model_id);
		$rs_list=$ModelTable->getShowList(array("user_id"=>(int)$user_id,"begin_time"=>$begin_time."-%"));
		$this->view->edu_list=$rs_list;
		$quarter_score=array(0,0,0,0);
		$year_score=0;
		foreach((array)$rs_list as $v){
			$year_score+=$v['score'];
			//convert month to quarter
			$quarter= Baogg_Date::month2quarter(substr($v['begin_time'],6,2));
			$quarter_score[$quarter]+=$v['score'];
		}
		$this->view->quarter_score=$quarter_score;
		$this->view->year_score=$year_score;
		$this->view->begin_time=$begin_time;
		$rs_list=$ModelTable->getShowList(array("user_id"=>(int)$user_id,"begin_time"=>$begin_time."-%"));
		$this->view->list=$rs_list;
		$this->view->quarter_list=array();
		$this->view->year_list=array();

		//echo '<pre>';print_r($rs_user[0]);exit;
	}
	
}
?>
